<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo</title>
</head>
<body>

</body>
<script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script src="jquery.min.js"></script>
<script>
    var domain = 'http://lianyou.hengdikeji.com/api/';
    function request(method,url,data,Callback,errCallback) {
        if(method=="post" || method=="POST"){
            data = JSON.stringify(data)
        }
        $.ajax({
            url:domain + url,
            type:method,
            contentType: "application/json", //必须有
            data:data,
            dataType:"JSON",
            success:function (res) {
                //接口错误返回
                if(res.code==0){
                    if(res.url){
                        //如有有返回URL，直接跳转
                        window.location.href=res.url
                    }else{
                        //弹窗提醒
                        alert(res.message)

                        if(typeof errCallback =="function"){
                            errCallback()
                        }
                    }

                }else if(res.code == -3){
                    //需要登录
                    window.location.href = res.url
                }else{
                    Callback(res.data,res.message)
                }
            }
        })
    }
    request("get","index/index",{id:1},function (res) {

    })

</script>
<script title="分享功能参考">
    var url = window.location.href;
    request('post','index/jssdk',{
        url:url,
    },function (res) {
        var shareTit = "分享标题";
        var shareDesc = "分享语";
        var sharelink = "http://lianyou.hengdikeji.com/lianyou/index.html";  //分享链接
        var shareImg = '';//分享图链接
        wx.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: res.appId, // 必填，公众号的唯一标识
            timestamp: res.timestamp, // 必填，生成签名的时间戳
            nonceStr: res.nonceStr, // 必填，生成签名的随机串
            signature: res.signature,// 必填，签名
            jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage'] // 必填，需要使用的JS接口列表
        });
        wx.ready(function () {
            //分享到朋友圈
            wx.onMenuShareTimeline({
                title: shareTit,
                desc: shareDesc,
                link: sharelink,
                imgUrl:shareImg,
                trigger: function (res) {
                },
                success: function (res) {
//                         popWin(3,'分享成功');
                    setTimeout(function(){
                        $rst = setShare();
                    }, 500)

                },
                cancel: function (res) {
                },
                fail: function (res) {
                    alert(JSON.stringify(res));
                }
            });
            wx.onMenuShareAppMessage({
                title: shareTit,
                desc: shareDesc,
                link: sharelink,
                imgUrl:shareImg,
                trigger: function (res) {
                },
                success: function (res) {
                    setTimeout(function(){
                        $rst = setShare();
                    }, 500)
                },
                cancel: function (res) {
                },
                fail: function (res) {
                    alert(JSON.stringify(res));
                }
            });
        })
    })
    function setShare(type) {
        request("POST",'index/share',{typeof:type},function (res) {

        })
    }
</script>
</html>